{{extend "req_layout.html"}}

{{block sub_menu}}
{{sub_menu(menu_items, 'ticket', 'risk')}}
{{end}}

{{block content_main}}
{{use "jquery", css_only=True}}
{{use "facebox"}}
{{use "jqutils", ajaxForm=True}}
{{link "ticket/ticket.css"}}
<style type="text/css">
.article {padding:10px;border:1px solid #ccc;}
.article .title {margin: 0 auto;}
.article .title h3 {padding: 0 0 0 120px;text-align: left;}
.article .title .title-info {padding: 0 0 0 120px;text-align: left; color:#999;}
.article span.normal {color:#000};
div.period {float:right;margin-top:-25px;margin-right:5px;}
.article fieldset {padding:10px;margin:10px;color:#333;border-top:#06c solid 1px;} 
.article fieldset.normal {padding:10px;margin:10px;color:#333;border:#06c solid 1px;} 
.article legend {color:#06c;font-weight:800;background:#fff;} 
</style>
{{from uliweb.utils.textconvert import text2html}}
<div class="content">
    <div class="article ui-corner-all">
        <div class="title">
            <h3>风险：{{=object.title}}</h3>
            <div class="title-info">
                由 <span>{{=object.submitter}}</span> 于 <span>{{=object.submit_date}}</span> 提出 |
                <span class="normal"><b>分类：</b></span><span class="tag">{{=object.get_display_value('category')}}</span> |
                <span class="normal"><b>状态：</b></span><span id="status" class="tag">{{=object.get_display_value('status')}}</span> |
                <span class="normal"><b>概率：</b></span><spanclass="tag">{{=object.get_display_value('probability')}}</span> |
                <span class="normal"><b>严重性：</b></span><spanclass="tag">{{=object.get_display_value('serious')}}</span> |
                <span class="normal"><b>是否需要上会：</b></span><spanclass="tag">{{=object.get_display_value('need_discuss')}}</span> |
            </div>
        </div>
        <fieldset class="normal">
          <legend class="normal">风险描述：</legend>
            <div>{{<< text2html(object.content) or '无内容'}}</div>
          </legend>
        </fieldset>
        <fieldset class="normal">
          <legend>影响结果：</legend>
            <div>{{<< text2html(object.affect) or '无内容'}}</div>
          </legend>
        </fieldset>
        <fieldset class="normal">
          <legend>缓解计划：</legend>
            <div>{{<< text2html(object.solve_desc) or '无内容'}}</div>
          </legend>
        </fieldset>
        <fieldset class="normal">
          <legend>应对方案：</legend>
            <div>{{<< text2html(object.resolusion) or '无内容'}}</div>
          </legend>
        </fieldset>
        <fieldset class="normal">
          <legend>基本信息：</legend>
            <table class="table" width="100%">
                <tr>
                    <td colspan="2"><b>责任人或单位：</b>{{=object.assigned}}</td>
                </tr>
                <tr>
                    <td width="50%"><b>关联准开发需求：</b>{{<< view_obj.result_fields['requirement']['display']}}</td>
                    <td width="50%"><b>关联任务：</b>{{<< view_obj.result_fields['task']['display']}}</td>
                </tr>
                <tr>
                    <td>
                        <b>所属条线：</b>{{<< view_obj.result_fields['tx']['display']}}
                        <b>所属开发中心：</b>{{<< view_obj.result_fields['kfzx']['display']}}
                        <b>所属系统：</b>{{<< view_obj.result_fields['owner_sys']['display']}}
                    </td>
                    <td><b>责任系统：</b>{{<< view_obj.result_fields['systems']['display']}}</td>
                </tr>
                <tr>
                    <td>
                        <b>所有人：</b>{{<< view_obj.result_fields['owner']['display']}}
                        <b>修改人：</b>{{<< view_obj.result_fields['modified_user']['display']}}
                    </td>
                    <td>
                        <b>修改时间：</b>{{<< view_obj.result_fields['modified_date']['display']}}
                    </td>
                </tr>
            </table>
          </legend>
        </fieldset>
        {{if object.can_modify(request.user) or request.user.is_superuser:}}
            <a class="btn btn-green" href="/ticket/risks/edit/{{=object.id}}">编辑</a>
            <a id="close_button" class="btn btn-green" href="/ticket/risks/close/{{=object.id}}" onclick="return confirm('确定要关闭当前记录吗？');">关闭</a>
            <a class="btn btn-green" href="/ticket/risks/add_solve/{{=object.id}}">添加解决方案</a>
        {{pass}}
        {{if request.user.is_superuser:}}
            <a class="btn btn-blue" href="/ticket/risks/delete/{{=object.id}}" onclick="return confirm('确定要删除当前记录吗？');">删除</a>
        {{pass}}
    </div>
    <div class="box box-panel">
        <h2>处理过程</h2>
        <div id="comments" class="box-body">
            <div class="box-bottom">
            <a class="btn btn-green" href="javascript:void(0)" id="add_comment">添加解决记录</a>
            </div>
        </div>
    </div>
    <script type="text/html" id="commentTemplate">
        <li>
            <div class="clearfix">
                <div class="comment-index">${index}</div>
                <div class="comment-body ${cls}">${comment}</div>
            </div>
            <div class="clear"></div>
            <div class="comment-footer">
                由 <font color="blue"><b>${modified_user}</b></font> 写于 ${modified_date}
            </div>
        </li>
    </script>
    <script type="text/javascript">
    
    var post_add_comment = function(r, prefix, task_id){
        if (r.success){
            show_message(r.message);
            jQuery(document).trigger('close.facebox');
            load_comments();
            
        } else if (!r.success){
            $('div.error-div').remove();
            show_message(r.message, 'error');
            $.each(r.data, function(key, value){
                var f, t, e, d;
                f = 'field_' + key;
                t = $('label[for='+f+']');
                e = $('<div class="ui-state-error error-div" style="border:0;"><span class="ui-icon ui-icon-info" style="float:left;"></span><span class="ui-state-error-text">' + value + '</span></div>');
                d = t.position();
                t.after(e);
            });
        }
    }
    
    var add_comment_click = function(){
        var a = $(this);
        var url = "/ticket/risks/add_comment/{{=object.id}}"
        $.facebox(function() {
            $.get(url, function(data) {
                $.facebox(data);
                $('#add_comment_form').ajaxForm(post_add_comment);
            });
        });
    }
    
    var load_comments = function(){
        $.ajax({
            type: "POST",
            url: "/ticket/risks/comments/{{=object.id}}",
            success: function(data){
                $('#comments').find('ul').remove();
                var ul = $('<ul class="comment-list"></ul>');
                ul.prependTo($('#comments'));
                $.each(data, function(index, value){
                    var comment = template($('#commentTemplate').html(), value).appendTo(ul);
                    comment.find('a.del_comment').click(function(event){
                        event.preventDefault();
                        var item = $(this);
                        if (confirm('确定要删除当前记录吗？')){
                            $.ajax({
                                type: "POST",
                                url: item.attr('href'),
                                success :function(r){
                                    if (r.success){
                                        show_message(r.message);
                                        load_comments();
                                    }else if (!r.success){
                                        show_message(r.message, 'error');
                                    }
                                }
                            });
                        }
                    });
                });
            }
        });
    }
    
    var close_risk = function(event){
        event.preventDefault();
        var self = $(this);
        $.ajax({
            type: "POST",
            url: self.attr('href'),
            success :function(r){
                if (r.success){
                    show_message(r.message);
                    $('#status').html(r.data.status).effect('highlight', 5000);
                }else if (!r.success){
                    show_message(r.message, 'error');
                }
            }
        });
        
    }
    
    $(function(){
        load_comments();
        $(function(){
            $.facebox.settings.loadingImage = '{{=url_for_static('facebox/loading.gif')}}'
            $.facebox.settings.closeImage = '{{=url_for_static('facebox/closelabel.png')}}'
            $('#add_comment').click(add_comment_click);
            $('#close_button').click(close_risk);
        });
    });
    </script>
</div>
<br/>

{{end}}
